package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.BoIntegralConfig;
import com.library.service.IBoIntegralConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 积分规则配置 信息操作处理
 *
 * @author wanghongjie
 * @date 2020-01-18
 */
@RestController
@RequestMapping("/library/boIntegralConfig")
public class BoIntegralConfigController extends BaseController {

    @Autowired
    private IBoIntegralConfigService boIntegralConfigService;

    /**
     * 查询积分规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoIntegralConfig boIntegralConfig) {
        startPage();
        List<BoIntegralConfig> list = boIntegralConfigService.selectBoIntegralConfigList(boIntegralConfig);
        return getDataTable(list);
    }

    /**
     * 导出积分规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:export')")
    @Log(title = "积分规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoIntegralConfig boIntegralConfig) {
        List<BoIntegralConfig> list = boIntegralConfigService.selectBoIntegralConfigList(boIntegralConfig);
        ExcelUtil<BoIntegralConfig> util = new ExcelUtil<BoIntegralConfig>(BoIntegralConfig.class);
        util.exportExcel(response, list, "积分规则配置数据");
    }

    /**
     * 获取积分规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(boIntegralConfigService.selectBoIntegralConfigById(id));
    }

    /**
     * 新增积分规则配置
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:add')")
    @Log(title = "积分规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoIntegralConfig boIntegralConfig) {
        return toAjax(boIntegralConfigService.insertBoIntegralConfig(boIntegralConfig));
    }

    /**
     * 修改积分规则配置
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:edit')")
    @Log(title = "积分规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoIntegralConfig boIntegralConfig) {
        return toAjax(boIntegralConfigService.updateBoIntegralConfig(boIntegralConfig));
    }

    /**
     * 删除积分规则配置
     */
    @PreAuthorize("@ss.hasPermi('library:boIntegralConfig:remove')")
    @Log(title = "积分规则配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boIntegralConfigService.deleteBoIntegralConfigByIds(ids));
    }
}
